package deng.hibernate.test;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

public abstract class HibernateHelper {
	
	public static void withAutoCommitSession(SessionFactory sessionFactory, SessionAction action) {
		Session session = sessionFactory.getCurrentSession();
		session.beginTransaction();
		action.onSession(session);
		session.getTransaction().commit();
	}
	
	public static interface SessionAction {
		public void onSession(Session session);
	}
	
}
